class Solution(object):
    def findLengthOfShortestSubarray(self, arr):
        n = len(arr)
        left = 1
        while left < n:
            if arr[left] - arr[left - 1] >= 0:
                left += 1
            else:
                break
        if left == n:
            return 0
        else:
            max_len = left
            left -= 1
            right = n - 1
            while right > 0:
                while left >= 0 and arr[right] < arr[left]:
                    left -= 1
                max_len = max(max_len, left + 1 + n - right)
                if arr[right] < arr[right - 1]:
                    break
                else:
                    right -= 1
            return n - max_len